package com.lhj.bootdemo.proxy;

import com.lhj.bootdemo.proxy.service.MockDemoClient;
import com.lhj.bootdemo.proxy.service.impl.MockDemoClientImpl;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Proxy;

/**
 * @author lhj
 * @version 1.0
 * @date 2022/4/17 8:46 上午
 * @description:
 */
@Slf4j
public class ProxyTester {

    public static void main(String[] args) {
        dynamicProxyTest();
    }


    public static void dynamicProxyTest(){

        MockDemoClient client = new MockDemoClientImpl();

        ClassLoader classLoader = ProxyTester.class.getClassLoader();

        Class[] classes = {MockDemoClient.class};

        DemoClientInvocationHandler handler = new DemoClientInvocationHandler(client);

        MockDemoClient proxy = (MockDemoClient) Proxy.newProxyInstance(classLoader, classes, handler);
        String hello = proxy.hello();

        log.info("代理调用hello方法，结果： "+hello);

    }
}
